package net.tomhe.android.tripfinder;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class ChooseSearchTypeActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		setDateButtonText();
		setTimeButtonText();
		final Spinner spinner = (Spinner) findViewById(R.id.timetype);
		final ArrayAdapter<CharSequence> adapter = ArrayAdapter
				.createFromResource(this, R.array.timetype,
						android.R.layout.simple_spinner_item);
		adapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
			public void onItemSelected(final AdapterView<?> parent,
					final View view, final int position, final long id) {
				Toast.makeText(ChooseSearchTypeActivity.this,
						String.format("Pos: %d, Id: %d", position, id),
						Toast.LENGTH_LONG).show();
			}

			public void onNothingSelected(final AdapterView<?> arg0) {
			}
		});
		setNewSearchListener();
		setSavedSearchListener();
	}

	private void setDateButtonText() {
		final Button button = (Button) findViewById(R.id.datebutton);
		final Calendar cal = Calendar.getInstance();
		button.setText(String.format("%4d-%02d-%02d", cal.get(Calendar.YEAR),
				cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)));
	}

	private void setTimeButtonText() {
		final Button button = (Button) findViewById(R.id.timebutton);
		final Calendar cal = Calendar.getInstance();
		button.setText(String.format("%02d:%02d",
				cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)));
	}

	private void setNewSearchListener() {
		final Button button = (Button) findViewById(R.id.newsearch);
		button.setOnClickListener(new OnClickListener() {
			public void onClick(final View v) {
			}
		});
	}

	private void setSavedSearchListener() {
		final Button button = (Button) findViewById(R.id.savedsearch);
		button.setOnClickListener(new OnClickListener() {
			public void onClick(final View v) {
			}
		});
	}
}